#!/bin/bash
#mysql 备份
MYSQL_CMD="/lhwl/app/mysql/bin/mysqldump"
MYSQL_USR="root"
MYSQL_PWD="passw0rd"
MYSQL_BAK="/lhwl/bin/sqldump/$(date +%Y%m%d%H%M%S)"
MYSQL_RMS="/lhwl/bin/sqldump"
FIND="/usr/bin/find"
MYSQL_MP=`/lhwl/app/mysql/bin/mysql -u root -ppassw0rd   -e "show databases;" | grep -v "/"   | grep  -v Database | grep -v mysql | grep -v performance_schema | grep -v information_schema | grep -v sys`

if [ ! -d $MYSQL_RMS ]; then
      mkdir -p $MYSQL_RMS
fi

if [ ! -d $MYSQL_BAK ];then
     mkdir -p $MYSQL_BAK
fi

/lhwl/app/mysql/bin/mysqldump -uroot -p'passw0rd' -h127.0.0.1 -P3306 --set-gtid-purged=OFF --all-databases  --events --ignore-table=mysql.events  --single-transaction   >$MYSQL_BAK/all-databases.sql
cp -r /lhwl/data/vhost/* $MYSQL_BAK/
echo "Backup success"

#for  DATABASENAME  in $MYSQL_MP
#do
#$MYSQL_CMD -u$MYSQL_USR -p$MYSQL_PWD $DATABASENAME >$MYSQL_BAK/${DATABASENAME}.sql
#$FIND $MYSQL_RMS/*  -mtime +6 -exec rm -rf {} \; 2>/dev/null
#echo "Backup success"
#done

tar -zcPf ${MYSQL_BAK}.tar.gz ${MYSQL_BAK}
$FIND $MYSQL_RMS/*  -mtime +60 -exec rm -rf {} \; 2>/dev/null
rm -fr ${MYSQL_BAK}

#为深圳职业做的修改